/**
 * 
 */
package com.github.sworm.android.killer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.graphics.Color;
import android.graphics.Paint.Style;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.RectShape;

import com.github.sworm.android.killer.objects.Preferences_;
import com.googlecode.androidannotations.annotations.EBean;
import com.googlecode.androidannotations.annotations.res.DrawableRes;
import com.googlecode.androidannotations.annotations.sharedpreferences.Pref;

/**
 * This class is the class that will give a new player, and a new enemy
 * 
 * - Have the logic to chose the graphics and the enemy level. - Have the logic
 * to know the type of Graphics and if the music is on.
 * 
 * @author nekun
 * 
 */
@EBean
public class GameManager {

	protected final static Logger logger = LoggerFactory
			.getLogger(GameManager.class);

	@Pref
	protected Preferences_ preferences;

	@DrawableRes
	protected Drawable monster;

	@DrawableRes
	protected Drawable xwing;

	/**
	 * Method that return the type of graphic set in the settings
	 * 
	 * @return can be 1 or 0
	 */
	public int getTypeGraphycs() {
		return preferences.graphic().get();
	}

	/**
	 * Method that return true/false if the music is on in the settings
	 * 
	 * true = music on false = music off
	 * 
	 * @return can be true/false
	 */
	public boolean isMusicOn() {
		return preferences.music().get();
	}

	/**
	 * Method that returns a new player cheking the type of Graphics selected
	 * 
	 * can be a vector or bitmap player
	 * 
	 * @return a drawable player
	 */
	public Drawable getPlayer() {
		Drawable drawablePlayer = null;

		switch (getTypeGraphycs()) {
		case 0: // Vector
			logger.debug("Player Vectorial");
			drawablePlayer = makePlayerVectorial();
			break;
		case 1: // BitMap
			logger.debug("Player BitMap");
			drawablePlayer = getPlayerBitmap();
			break;
		default:
			logger.debug("Player Bitmap - Default");
			drawablePlayer = getPlayerBitmap();
			break;
		}

		return drawablePlayer;
	}

	/**
	 * Method that returns a new Enemy cheking the type of the Graphics selected
	 * 
	 * can be vector or bitmap enemy
	 * 
	 * @return
	 */
	// TODO enemy level
	public Drawable getEnemy() {
		Drawable drawableEnemy = null;

		switch (getTypeGraphycs()) {
		case 0: // Vector
			logger.debug("Enemy Vectorial");
			drawableEnemy = makeEnemyVectorial();
			break;
		case 1: // BitMap
			logger.debug("Enemy Bitmap");
			drawableEnemy = getEnemyBitmap();
			break;
		default:
			logger.debug("Enemy Bitmap - default");
			drawableEnemy = getEnemyBitmap();
			break;
		}

		return drawableEnemy;
	}

	private Drawable getEnemyBitmap() {
		return monster;
	}

	/**
	 * Method that return a vectorial enemy
	 * 
	 * @return a drawable vectorial enemy
	 */
	private Drawable makeEnemyVectorial() {
		ShapeDrawable dShapeDrawableEnemy = new ShapeDrawable(new OvalShape());
		dShapeDrawableEnemy.getPaint().setColor(Color.WHITE);
		dShapeDrawableEnemy.getPaint().setStyle(Style.STROKE);
		dShapeDrawableEnemy.setIntrinsicWidth(20);
		dShapeDrawableEnemy.setIntrinsicHeight(20);
		return dShapeDrawableEnemy;
	}

	/**
	 * Method that returns a Vectorial Player
	 * 
	 * @return a Drawable Vectorial Player
	 */
	private Drawable makePlayerVectorial() {
		ShapeDrawable dShapeDrawablePlayer = new ShapeDrawable(new RectShape());
		dShapeDrawablePlayer.getPaint().setColor(Color.RED);
		dShapeDrawablePlayer.getPaint().setStyle(Style.STROKE);
		dShapeDrawablePlayer.setIntrinsicHeight(20);
		dShapeDrawablePlayer.setIntrinsicWidth(30);
		return dShapeDrawablePlayer;
	}

	/**
	 * Method that returns a BitMap player
	 * 
	 * @return return a Drawable BITMAP player
	 */
	// TODO should choose the ship
	private Drawable getPlayerBitmap() {
		return xwing;
	}

}